#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <map> 

#define flr(x, l, r) for (int x = l; x <= r; ++x)
#define frl(x, r, l) for (int x = r; x >= l; --x)
#define fmp(x, t) for (int x = h[t]; ~x; x = ne[x])
#define LL long long
#define mt memset
#define my memcpy
#define szf sizeof
#define INF 0x3f3f3f3f
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector
#define pb push_back
#define sz size
#define PII pair<int, int>
#define x first
#define y second
#define P_q priority_queue
#define ft front
#define pf push_front
#define popf pop_front
#define it insert
#define ct count

using namespace std;

const int N = 30, M = 100;

int n;
int h[N], e[M], ne[M], w[M], idx;
int dist[N], num[N], r[N];
int q[N], cnt[N];
bool st[N];

void add(int a, int b, int c) {
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

void build(int c) {
    mt(h, -1, szf h), idx = 0;
    
    flr (i, 1, 24) add(i - 1, i, 0), add(i, i - 1, -num[i]);
    flr (i, 8, 24) add(i - 8, i , r[i]);
    flr (i, 1, 7) add(i + 16, i, r[i] - c);
    add(0, 24, c), add(24, 0, -c);
}

bool spfa(int c) {
    build(c);
    
    mt(dist, -0x3f, szf dist);
    mt(cnt, 0, szf cnt);
    mt(st, 0, szf st);
    
    int hh = 0, tt = 1;
    dist[0] = 0, q[0] = 0, st[0] = true;
    
    while (hh != tt) {
        int t = q[hh ++ ];
        if (hh == N) hh = 0;
        st[t] = false;
        
        fmp (i, t) {
            int j = e[i];
            
            if (dist[j] < dist[t] + w[i]) {
                dist[j] = dist[t] + w[i];
                cnt[j] = cnt[t] + 1;
                if (cnt[j] >= 25) return true;
                
                if (!st[j]) {
                    q[tt ++ ] = j;
                    if (tt == N) tt = 0;
                    st[j] = true;
                }
            }
        }
    }
    
    return false;
}

int main() {
    int T;
	in(T);
	
	while (T -- ) {
	    flr (i, 1, 24) in(r[i]);
	    in(n);
	    mt(num, 0, szf num); 
	    
	    while (n -- ) {
	        int t;
	        in(t);
	        num[t + 1] ++ ;
	    }
	    
	    bool flag = false;
	    flr (i, 0, 1000)
	        if (!spfa(i)) {
	            flag = true;
	            out(i), pn;
	            bk;
	        }
	   
	    if (!flag) puts("No Solution");
	}
	
    return 0;
}                                                